/**
 * @author sahsharm
 */
(function($) {
	var source;
	var template;
	var id = 0, cache = [];

	Handlebars.registerHelper("bindData", function(data) {
		var dataKey = id++;
		cache[dataKey] = data;
		return "data-handlebar-id=" + dataKey;
	})

	Handlebars.getBoundData = function(handlebarId) {
		if( typeof (handlebarId) !== "string") {
			handlebarId = handlebarId.getAttribute("data-handlebar-id");
		}
		return cache[handlebarId];
	};
	var context = {
		links : [{
			name : "Dashboard",
			href : "#",
			load : "course_main.html"
		}, {
			name : "Courses",
			href : "#",
			load : "../course/courseoffering_search.html"
		}, {
			name : "Profile",
			href : "#",
			load : "course_main.html"
		}, {
			name : "My Network",
			href : "#",
			load : "../course/courseoffering_creation_wizard.html"
		}]
	};
	
	$.get("./template/main_links.txt", function(data) {
		$(data).filter('script[type="text/x-handlebars"]').each(function() {
			template = Handlebars.compile($(this).html());
		});
		var genHTML = template(context);
		$("#links-container").html(genHTML).on("click", "li", function() {
			$('#holder').load(Handlebars.getBoundData(this).load);
		});
	});
	
			
})(jQuery);
